package edu.hitwh.record;

import java.sql.Timestamp;

import edu.hitwh.entity.Transaction;
import edu.hitwh.entity.BorrowTransactionStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TransactionRecord {
    private Long id;
    private BorrowerRecord borrower;
    private BookRecord book;
    private Timestamp borrowDate;
    private BorrowTransactionStatus status;
    private Timestamp returnDate;

    public static TransactionRecord fromEntity(Transaction transaction) {
        return TransactionRecord.builder()
                .id(transaction.getId())
                .book(BookRecord.fromEntity(transaction.getBook()))
                .borrower(BorrowerRecord.fromEntity(transaction.getBorrower()))
                .borrowDate(transaction.getBorrowDate())
                .status(transaction.getStatus())
                .returnDate(transaction.getReturnDate())
                .build();
    }

    public Transaction toEntity() {
        return Transaction.builder()
                .id(id)
                .borrower(borrower.toEntity())
                .book(book.toEntity())
                .borrowDate(borrowDate)
                .status(status)
                .returnDate(returnDate)
                .build();
    }
}
